package com.yalemang.framework.base

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import com.yalemang.framework.utils.PermissionUtils
import com.yalemang.framework.utils.ViewBindingUtils

abstract class BaseActivity<VB: ViewBinding, P : BasePresenter<*, *>> : AppCompatActivity(), BaseView {

    protected lateinit var mPresenter : P
    protected lateinit var mBinding: VB
    private lateinit var permissionUtils: PermissionUtils

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        permissionUtils = PermissionUtils(this)
        mBinding = ViewBindingUtils.getViewBinding(this, layoutInflater)!!
        setContentView(mBinding.root)
        initMVP()
        initData()
        initView()
    }

    fun startCheckFileReadWritePermission(callback: (Boolean)->Unit) {
        permissionUtils.startCheckFileReadWritePermission(permissionCallback = callback)
    }

    fun startCheckPermission(permissionList: MutableList<String>, callback: (Boolean) -> Unit) {
        permissionUtils.checkPermissions(permissionList, callback)
    }

    protected abstract fun initData()

    protected abstract fun initView()

    protected abstract fun initMVP()

    override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<out String>,
        grantResults: IntArray
    ) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        permissionUtils.onRequestPermissionsResult(requestCode, permissions, grantResults)
    }
}